﻿namespace Pp.UI.Controllers
{
    using System;
    using System.Web.Mvc;
    using Core;
    using Dto;
    using Globalization;
    using Repository;


    public class ProfileController : BaseController
    {
        public ActionResult Index(string id)
        {
            ViewData["Title"] = Res.Menu_Profile;
            if (string.IsNullOrEmpty(id))
                id = User.Identity.Name;
            var wallItem = UserRepository.GetWallItem(id, (id == User.Identity.Name));
            return View(wallItem);
        }
        [HttpPost]
        [Authorize]
        public JsonResult Like(MLike mLike)
        {
            if (!mLike.Id.HasValue)
                return Json(Result<int>.AsError(Res.Message_Object_NoFound_For_Like));
            Result<int> result = Result<int>.AsSuccess(0);
            if (mLike.LikeType == LikeType.Profile)
                result = UserRepository.Like(mLike.Id, User.Identity.Name);
            if (mLike.LikeType == LikeType.Project)
                result = ProjectRepository.Like(mLike.Id, User.Identity.Name);
            return Json(result);
        }
        [HttpPost]
        [Authorize]
        public JsonResult Dislike(MLike mLike)
        {
            if (!mLike.Id.HasValue)
                return Json(Result<int>.AsError(Res.Message_Object_NoFound));
            Result<int> result = Result<int>.AsSuccess(0);
            if (mLike.LikeType == LikeType.Profile)
                result = UserRepository.Dislike(mLike.Id, User.Identity.Name);
            if (mLike.LikeType == LikeType.Project)
                result = ProjectRepository.Dislike(mLike.Id, User.Identity.Name);
            return Json(result);
        }


    }
}
